package com.zh.core;

import java.util.*;

/**
 * Created by zhaohui on 2019/9/7
 * Description:
 */
public class MapTest {

    public static void main(String[] args) {
        Map<Integer, String> users = new HashMap<>();
        users.put(1, "John");
        users.put(2, "Mike");
        users.put(3, "Lucy");
        System.out.println(users);
        users.put(1, "new John");
        users.forEach((k, v) ->
                System.out.println("k=" + k + ", value=" + v));
        Set<Integer> keySet = users.keySet();
        Collection<String> values = users.values();
        Set<Map.Entry<Integer, String>> entrySet = users.entrySet();
        System.out.println(keySet);
        System.out.println(values);
        System.out.println(entrySet);
        System.out.println(users.getOrDefault(4, "NotFound"));
        for (Map.Entry<Integer, String> entry : entrySet) {
            Integer key = entry.getKey();
            String value = entry.getValue();
            System.out.println("key is " + key + ", value is " + value);
        }
        System.out.println("---------------");
        Map<String, String> product = new HashMap<>();
        product.put("John", "John");
        product.put("Mike", "Mike");
        product.put("Lucy", "Lucy");
        product.forEach((k, v) ->
                System.out.println(k));
        System.out.println("---------------");
        Map<String, String> product2 = new LinkedHashMap<>();
        product2.put("John", "John");
        product2.put("Mike", "Mike");
        product2.put("Lucy", "Lucy");
        product2.forEach((k, v) ->
                System.out.println(k));

    }

}
